package com.spring.demo.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author ZhuYouBin
 * @version 1.0.0
 * @Date: 2022/10/3 22:40
 * @Description
 */
public class BeanDemoTwo implements ApplicationContextAware, BeanFactoryAware, BeanNameAware, InitializingBean {
    private String name;

    public BeanDemoTwo() {
        System.out.println("BeanDemoTwo实例化: 执行 BeanDemoTwo 类的构造方法...");
    }

    public void init() {
        System.out.println("BeanDemoTwo初始化: 执行 BeanDemoTwo 类的 init 初始化方法...");
    }

    public void destroyMethod() {
        System.out.println("BeanDemoTwo销毁方法: 执行 BeanDemoTwo 类的 destroyMethod 初始化方法...");
    }

    public void setName(String name) {
        this.name = name;
        System.out.println("BeanDemoTwo属性赋值: 执行 BeanDemoTwo 类的属性赋值方法...");
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("BeanDemoTwo-->BeanNameAware: 当前Bean的名称是: " + beanName);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("BeanDemoTwo-->InitializingBean: 执行 afterPropertiesSet 方法...");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("BeanDemoTwo-->BeanFactoryAware: 执行 setBeanFactory 方法...");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("BeanDemoTwo-->ApplicationContextAware: 执行 setApplicationContext 方法...");
    }
}
